﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Data;

namespace AirlineCommon
{
    public abstract class PassengerCommon
    {
        private string _PNRNo;

        public string PNRNo
        {
            get { return _PNRNo; }
            set { _PNRNo = value; }
        }
        private string _FlightNo;

        public string FlightNo
        {
            get { return _FlightNo; }
            set { _FlightNo = value; }
        }
        private DateTime _TravelDate;

        public DateTime TravelDate
        {
            get { return _TravelDate; }
            set { _TravelDate = value; }
        }
        private string _FName;

        public string FName
        {
            get { return _FName; }
            set { _FName = value; }
        }
        private string _LName;

        public string LName
        {
            get { return _LName; }
            set { _LName = value; }
        }
        private int _Age;

        public int Age
        {
            get { return _Age; }
            set { _Age = value; }
        }
        private string _Gender;

        public string Gender
        {
            get { return _Gender; }
            set { _Gender = value; }
        }
        private string _Class;

        public string Class
        {
            get { return _Class; }
            set { _Class = value; }
        }
       
        private string _MealPref;

        public string MealPref
        {
            get { return _MealPref; }
            set { _MealPref = value; }
        }
       
        private string _Status;

        public string Status
        {
            get { return _Status; }
            set { _Status = value; }
        }
        public abstract void InsertPassenger();
        public abstract int InsertPassenger(SqlTransaction trans);
        public  int UpdatePassengerStatus(SqlTransaction trans, string PNRNo, string status)
        {
            try
            {
                //SqlConnection conn = new SqlConnection(DAL.DatabaseProvider.AirlineConnectionString);
                string UpdateSql = "Update Passengers set Status=@Status Where PNRNo=@PNRNo";
                SqlParameter pStatus = new SqlParameter("@Status", status);
                SqlParameter pPNRno = new SqlParameter("@PNRNo", PNRNo);
                int HowManyRows = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, UpdateSql, pStatus,
                       pPNRno);
                return HowManyRows;
            }
            catch
            {
                return -1;
            }
        }
        public PassengerCommon GetPassengerByPNRNo(string PNRNo)
        {
            SqlConnection conn = new SqlConnection(DAL.DatabaseProvider.AirlineConnectionString);
            try
            {
                string sql = "select * from Passengers Where PNRNo='" + PNRNo + "'";
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql);
                if (ds.Tables[0].Rows.Count  == 0) return null;
                DataRow dr=ds.Tables[0].Rows[0];
                _PNRNo = dr["PNRNo"].ToString();
                _FlightNo = dr["FlightNo"].ToString();
                _TravelDate = DateTime.Parse(dr["TravelDate"].ToString());
                _FName = dr["FName"].ToString();
                _LName = dr["LName"].ToString();
                _Age = int.Parse(dr["Age"].ToString());
                _Gender = dr["Gender"].ToString();
                _Class = dr["Class"].ToString();
                _Status = dr["Status"].ToString();
                _MealPref = dr["MealPref"].ToString();
                return this;

            }
            catch
            {
                return null;
            }
            conn.Close();
        }

    }
}
